package com.sea.base.ext.view

import android.app.Dialog
import androidx.lifecycle.Lifecycle
import com.sea.base.dialog.BaseDialog
import com.sea.base.ext.global.throwIfDebug
import com.sea.base.ext.obs.doOnDestroyed

/**
 * 判断和添加了生命周期
 */
fun Dialog.showWrapLifecycle(lifecycle: Lifecycle) {
    if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
        "无法show，当前state：${lifecycle.currentState}".throwIfDebug()
        return
    }
    this.show()
    if (this !is BaseDialog) {
        lifecycle.doOnDestroyed {
            dismiss()
        }
    }
}